'use strict'

const fs = require('fs')
const path = require('path')
const paths = require('./paths')

const NODE_ENV = process.env.NODE_ENV
if(!NODE_ENV){
    throw new Error(
        'The NODE_ENV environment variable is required but was not specified.'
    )
}
const REACT_APP = /^REACT_APP_/i;


function getClientEnvironment(publicUrl){
    const raw = Object.keys(process.env)
    .filter( key => REACT_APP.test(key))
    .reduce(
        (env,key) =>{
            env[key] = process.env[key];
            return env
        },
        {
            NODE_ENV:process.env.NODE || 'development',
            PUBLIC_URL:publicUrl,
            STATIC_ENV:process.env.STATIC_ENV || 'development'
        }
    )
    return{
        raw
    }
}

module.exports = getClientEnvironment